const express = require('express')
const router = express.Router()
const db = require('../../connection/Connection')
const jwt = require('jsonwebtoken')
const SECRET = 'asdfta219*&%^jWJSHFJ'


router.post('/deleteUser', async (req, res) => {
    //token
    const result = jwt.verify(req.body.token, SECRET)
    let sql = 'select departmentId from user_role where username = ?'
    db.base(sql, result.username, response_temp => {
        if(response_temp!=null&&response_temp[0].departmentId == 999){
            sql = 'DELETE FROM user WHERE username = ?'
            console.log(req.body)
            db.base(sql,req.body.username,response=>{
                if(response!=null&&response.affectedRows === 1){
                        res.json({
                            code:200,
                            reason: response
                        })
                }else{
                    res.json({
                        result: "error",
                        reason: "无权限"
                    })
                }
            })
        }
       
       
    })
})

module.exports = router
